package web1.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import web1.bean.Group;
import web1.bean.user;


/**
 * Servlet implementation class elServlet
 */
@WebServlet(asyncSupported = true, urlPatterns = { "/s/el" })
//@WebServlet("/elServlet")
public class elServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public elServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//response.getWriter().append("Served at: ").append(request.getContextPath());
		request.setAttribute("hello", "hello world");
		//结构
		Group group=new Group();
		group.setName("提高班八期");
		
		user u=new user();
		u.setName("xh");
		u.setAge(18);
		u.setGroup(group);
		request.setAttribute("user", u);
		
		//map
		Map map=new HashMap();
		map.put("key1", "value1");
		map.put("key2", "value2");
		request.setAttribute("map", map);
		
		//字符串数组
        String[] strArray=new String[]{"六期","七期","八期","九期","十期"};
        request.setAttribute("str_array", strArray);
               
        //对象数组
        user[] users=new user[5];
        for (int i = 0; i < users.length; i++) {
            users[i]=new user();
            users[i].setName("juyahong("+i+")");
        }
        request.setAttribute("users", users);
              
        //list
        List groupList=new ArrayList();
        for (int i = 6; i < 12; i++) {
            Group group2=new Group();
            group2.setName("提高班第"+i+"期");
            groupList.add(group2);
        }
        request.setAttribute("groupList", groupList);
                
        //empty
        request.setAttribute("tgb6", "");
        request.setAttribute("tgb7", new ArrayList());
        request.setAttribute("tgb8", "提高班第八期");
        request.setAttribute("tgb9", null);
 
        //request的分发器
        request.getRequestDispatcher("/day0905/el1.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}
	public void destroy() {
		System.out.println("JstlElServlet.销毁！");
		super.destroy();
	}

}
